package network;

import java.net.InetAddress;
import java.net.UnknownHostException;

import gui.Main.GUICore;

public class GUICoreProxy extends GUICore {
	private GlobalObjectId globalObjectId;

	public GUICoreProxy(GlobalObjectId globalObjectId) {
		this.globalObjectId = globalObjectId;
	}

	public int refresh(int p0){
        String[] parameterTypeNames = new String[1];
        parameterTypeNames[0] = "int";
        Object[] actualParameters = new Object[1];
        actualParameters[0] = p0;
        Command command = new Command(globalObjectId.getLocalObjectId(), "gui.Main.GUICore", "refresh", parameterTypeNames, actualParameters, true);
        Object result = PeerCommunicator.getSingleton().sendSynchronous(globalObjectId, command);
        return (Integer)result;
    }

	public network.LocalObjectId getLocalObjectId() {
		String[] parameterTypeNames = new String[0];
		Object[] actualParameters = new Object[0];
		Command command = new Command(globalObjectId.getLocalObjectId(), "gui.Main.GUICore", "getLocalObjectId", parameterTypeNames, actualParameters, true);
		Object result = PeerCommunicator.getSingleton().sendSynchronous(globalObjectId, command);
		return (network.LocalObjectId) result;
	}

	public int hashCode() {
		String[] parameterTypeNames = new String[0];
		Object[] actualParameters = new Object[0];
		Command command = new Command(globalObjectId.getLocalObjectId(), "java.lang.Object", "hashCode", parameterTypeNames, actualParameters, true);
		Object result = PeerCommunicator.getSingleton().sendSynchronous(globalObjectId, command);
		return (Integer) result;
	}

	public boolean equals(java.lang.Object p0) {
		String[] parameterTypeNames = new String[1];
		parameterTypeNames[0] = "java.lang.Object";
		Object[] actualParameters = new Object[1];
		actualParameters[0] = p0;
		Command command = new Command(globalObjectId.getLocalObjectId(), "java.lang.Object", "equals", parameterTypeNames, actualParameters, true);
		Object result = PeerCommunicator.getSingleton().sendSynchronous(globalObjectId, command);
		return (Boolean) result;
	}

	public java.lang.String toString() {
		String[] parameterTypeNames = new String[0];
		Object[] actualParameters = new Object[0];
		Command command = new Command(globalObjectId.getLocalObjectId(), "java.lang.Object", "toString", parameterTypeNames, actualParameters, true);
		Object result = PeerCommunicator.getSingleton().sendSynchronous(globalObjectId, command);
		return (java.lang.String) result;
	}

	public Object writeReplace() {
		return this;
	}
	
	public Object readResolve(){
		try {
			if(globalObjectId.onSameMachineAs(new GlobalObjectId(InetAddress.getLocalHost().getHostAddress(), PortNumber.getApplicationsPortNumber(), null))){
				return ObjectDB.getSingleton().getValue(globalObjectId.getLocalObjectId());
			}
			else{
				return this;
			}
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
}
